home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
DB_CLIPP
/
0411.ZIP
/
STRVALS.C
< prev
next >
Wrap
Text File
|
1985-10-11
|
4KB
|
190 lines
/*
* Program to read the keyboard and return the hex and decimal equivalent.
*/
int scr_cols,
scr_rows,
scr_mode,
scr_page,
scr_attr;
#include "stdio.h"
main(argc,argv)
int argc;
char *argv[];
{
extern int scr_cols,
scr_rows,
scr_mode,
scr_page,
scr_attr;
char headmsg[61];
int inchar,
lastrow,
lastcol,
mode,
page,
cntr,
attr,
finished,
lopart,
medpart,
hipart,
redblu,
magblu,
grnblu,
yelblu,
blue;
/*
* Check if version information was asked for
*/
if (argc > 1)
{
if (argv[1][0] == '#')
{
puts("\n");
puts("PROGRAM: STRVALS\n");
puts("Author : Peter Townsend\n");
puts("Date : 11Oct85\n");
puts("Version: 1.0\n");
exit(0);
}
}
/*
* Initialise
*/
redblu = 0x1c;
yelblu = 0x1e;
magblu = 0x1d;
grnblu = 0x1a;
blue = 0x1;
strcpy(headmsg,"Enter a string to see its hex and decimal values");
/*
* Initialise screen handling facilities
*/
scr_setup();
/*
* Store current screen state
*/
mode = scr_mode;
attr = scr_attr;
page = scr_page;
/*
* Set new screen state
*/
scr_setmode(3);
scr_color(0,blue);
scr_attr = redblu;
scr_clr();
/*
* Set cursor position to 3rd line
*/
lastrow = 2;
lastcol = 0;
/*
* Print the function heading at the top of the screen
*/
cntr = (scr_cols - strlen(headmsg)) / 2;
scr_rowcol(0,cntr);
for(cntr=0;cntr<strlen(headmsg);cntr++)
{
scr_co_atr(headmsg[cntr],grnblu);
scr_rowcol(0,scr_scol()+1);
}
scr_rowcol(lastrow,lastcol+2);
inchar = ci();
while (inchar != 0xd)
{
while (inchar != 0xd)
{
/*
* Print the character
*/
scr_co_atr(inchar,magblu);
/*
* Seperate the character into hi and lo parts of a hex value
*/
hipart = inchar / 0x10;
lopart = inchar % 0x10;
if ((hipart >= 0) && (hipart <=9))
{
hipart = hipart + '0';
}
else
{
hipart = hipart + 'A' - 0xa;
}
if ((lopart >= 0) && (lopart <=9))
{
lopart = lopart + '0';
}
else
{
lopart = lopart + 'A' - 0xa;
}
/*
* Print the hex value underneath the character
*/
scr_rowcol(lastrow+1,lastcol+1);
scr_co_atr(hipart,yelblu);
scr_rowcol(lastrow+1,lastcol+2);
scr_co_atr(lopart,yelblu);
/*
* Seperate the character into hi, med, and lo parts of a dec value
*/
hipart = inchar / 0x64;
medpart = (inchar % 0x64) / 0xa;
lopart = (inchar % 0x64) % 0xa;
hipart = hipart + '0';
lopart = lopart + '0';
medpart = medpart + '0';
/*
* Print the dec value underneath the hex values
*/
scr_rowcol(lastrow+2,lastcol);
scr_co_atr(hipart,redblu);
scr_rowcol(lastrow+2,lastcol+1);
scr_co_atr(medpart,redblu);
scr_rowcol(lastrow+2,lastcol+2);
scr_co_atr(lopart,redblu);
/*
* Check row/column values for input of next character
*/
lastcol = lastcol + 4;
if (lastcol >= scr_cols)
{
lastcol = 0;
lastrow = lastrow + 4;
if ((lastrow+1) >= scr_rows)
{
scr_scup();
scr_scup();
scr_scup();
scr_scup();
lastrow = lastrow - 4;
}
}
scr_rowcol(lastrow,lastcol+2);
inchar = ci();
}
lastcol = 0;
lastrow = lastrow + 4;
if (lastrow >= scr_rows)
{
scr_scup();
scr_scup();
scr_scup();
scr_scup();
lastrow = lastrow - 4;
}
scr_rowcol(lastrow,lastcol+2);
inchar = ci();
}
/*
* Restore previous screen environment
*/
scr_setmode(mode);
scr_attr = attr;
scr_page = page;
scr_clr();
exit(0);
}